﻿using System;
using System.Collections;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace DrWileyO_REDACTED_Adventure
{
    class PowerUp
    {
        AnimatedSprite mAnimatedSprite;
        Texture2D debugHitBox;
        Vector2 mPosition;

        private double lastAnimateUpdate;
        private int animationDir = 1;
        public bool toRemove = false;

        public static float ENERGY_GAIN = 0.05f;

        public Rectangle hitBox;

        PowerUp(Texture2D atlas, Vector2 pos, Texture2D debug)
        {
            debugHitBox = debug;
            mAnimatedSprite = new AnimatedSprite(atlas,pos, 1, 3);
            hitBox = new Rectangle((int)pos.X, (int)pos.Y, mAnimatedSprite.Width, mAnimatedSprite.Height);
            mPosition = pos;
        }

        public void Update(GameTime gTime)
        {
            if (lastAnimateUpdate == 0)
                lastAnimateUpdate = gTime.TotalGameTime.TotalMilliseconds;

            if (gTime.TotalGameTime.TotalMilliseconds - lastAnimateUpdate > 150)
            {
                if (mAnimatedSprite.currentFrame == 2)
                    animationDir = -1;
                else if (mAnimatedSprite.currentFrame == 0)
                    animationDir = 1;

                mAnimatedSprite.currentFrame += animationDir;

                lastAnimateUpdate = gTime.TotalGameTime.TotalMilliseconds;
            }
        }

        public void Draw(GameTime gTime, SpriteBatch sBatch, float alpha)
        {
            if(!toRemove)
                mAnimatedSprite.Draw(sBatch);
          //  sBatch.Draw(debugHitBox, mPosition, Color.White);
        }

        public static ArrayList GetLevel(Texture2D atlas, Texture2D debug)
        {
            ArrayList powerUps = new ArrayList();

            powerUps.Add(new PowerUp(atlas, new Vector2(100, 420), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(170, 420), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(30, 420), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(30, 292), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(200, 292), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(170, 164), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(240, 164), debug));

            powerUps.Add(new PowerUp(atlas, new Vector2(540, 400), debug));

            powerUps.Add(new PowerUp(atlas, new Vector2(540, 280), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(500, 280), debug));

            powerUps.Add(new PowerUp(atlas, new Vector2(680, 350), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(680, 450), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(750, 350), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(750, 450), debug));

            powerUps.Add(new PowerUp(atlas, new Vector2(20, 15), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(60, 15), debug));

            powerUps.Add(new PowerUp(atlas, new Vector2(750, 15), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(850, 15), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(950, 15), debug));
            //powerUps.Add(new PowerUp(atlas, new Vector2(750, 15), debug));


            powerUps.Add(new PowerUp(atlas, new Vector2(960, 576 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1088, 576 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1216, 576 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1344, 576 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1472, 576 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1600, 448 - atlas.Height), debug));

            powerUps.Add(new PowerUp(atlas, new Vector2(1088, 192 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1088, 320 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1088, 448 - atlas.Height), debug));



            powerUps.Add(new PowerUp(atlas, new Vector2(1472, 576 - atlas.Height), debug));


            powerUps.Add(new PowerUp(atlas, new Vector2(1216, 256 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1350, 256 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1450, 256 - atlas.Height), debug));

            powerUps.Add(new PowerUp(atlas, new Vector2(1216, 384 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1350, 384 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1450, 384 - atlas.Height), debug));

            powerUps.Add(new PowerUp(atlas, new Vector2(1728, 512 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(1850, 512 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(2000, 512 - atlas.Height), debug));

            powerUps.Add(new PowerUp(atlas, new Vector2(2048, 128 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(2048, 256 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(2048, 384 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(2248, 64 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(2248, 192 - atlas.Height), debug));
            powerUps.Add(new PowerUp(atlas, new Vector2(2248, 320 - atlas.Height), debug));
            
            return powerUps;
        }

        public void Remove()
        {
            toRemove = true;
            hitBox = Rectangle.Empty;
        }
    }
}
